<?php

session_start();

require_once ("../../../db.php");


if (!isset($_SESSION['uid']) || ($_SESSION['type'] != 'student')) {
    die('Not logged in as an student user');
}

$sql = 'SELECT * FROM groupparticipants WHERE participantid=?';
$sth = $db->prepare($sql);
$sth->execute(array($_SESSION['uid'])); // get the group ID and check if user is in a group
$row = $sth->fetch();
if (!$row) {
    echo json_encode(array('error' => 'Du er ikke i noen gruppe'));
} else {
    $sql = 'SELECT * FROM groupparticipants WHERE groupid=?';   // select all group members 
    $sth = $db->prepare($sql);
    $sth->execute(array($row[0]));
    $row1 = $sth->fetchAll();
    
    $sql1 = 'SELECT * FROM projectgroups WHERE id=?';   // select project group
    $sth1 = $db->prepare($sql1);
    $sth1->execute(array($row[0]));
    $row2 = $sth1->fetch();
    echo json_encode(array($row1,$row2));   // return the members and group info
}
?>
